<template>
<view>
<view class="modle_1_nav" style="display:none;">
	<view v-for="(item, index) in table" :key="index" @tap="ActiveClick" :class="'modle_1_nav_modle ' + (activeIndex==index?'modle_1_nav_active':'')" :data-index="index" :style="'width:' + nav_width + '%'">{{item}}
		<view class="modle_1_nav_modle_border" v-if="activeIndex==index"></view>
	</view>
</view>
<!-- <view class="nav"></view> -->
<view v-for="(item, index) in carslist" :key="index" class="modle_border" v-if="carslist.length>0">
	<view class="modle">
		<image @tap="detile" class="modle_img" :data-id="item.id" :src="item.img_patch"></image>
		<view class="modle_name">
			<view @tap="detile" class="modle_name_left" :data-id="item.id">{{item.name}}  {{item.agelimit<1?'准新车':item.agelimit+'年车'}}<>
			</text>undefined</tag>
		</text></view>
		<view class="modle_time">
			<!-- {{item.toptype}} -->
		</view>
		<view class="modle_btn_view" v-if="item.status==3">
			<!-- {{item.status==3?'已发布':'被下架'}} -->
			<button @tap="upcar" class="modle_chexing_btnsc btn_active" :data-id="item.id">编辑</button>
			<button @tap="makeshelf" class="modle_chexing_btnsc btn_active" :data-id="item.id" :data-index="index" style="margin-right:20rpx;display:none;">{{item.status==3?'下架':'上架'}}</button>
			<!-- <button bindtap="delcar" class="modle_chexing_btnsc" data-id="{{item.id}}" data-index="{{index}}" style="margin-right:20rpx;">删除</button> -->
        <button @tap="downcar" class="modle_chexing_btnsc" :data-id="item.id" :data-index="index" style="margin-right:20rpx;">下架</button>
			<form @submit="upthiscar" :data-id="item.id" :data-index="index" reportSubmit="true" style="display:none;">
				<button class="modle_chexing_btnsc btn_active" form-type="submit" style="margin-right:20rpx;">置顶</button>
			</form>
		</view>
	</view>
</view>
<block v-if="carslist.length<=0">
	<!--<import src="/pages/data_null/index.wxml"></import>-->
	<view>
		<block data-type="template" data-is="title" data-attr="title:'暂无查看数据'">
    <view class="zanwushuju_border">
        <image class="zanwushuju_border_img" src="/static/pages/image/none_message.png"></image>
        <view class="zanwushuju_border_title">{{'暂无收藏数据'}}</view>
    </view>
</block>
	</view>
</block></view>
</view>
</template>

<script>
var app = getApp();

export default {
  data() {
    return {
      userinfo: [],
      settopfee: 0,
      settoptime: 0,
      carslist: [],
      table: ["全部", "车辆", "配件"],
      activeIndex: 0,
      nav_width: "",
      onshelffee: "",
      dropdown: 1,
      page: 1
    };
  },

  components: {},
  props: {},
  onLoad: function () {
    var t = this;
    t.setData({
      nav_width: 100 / t.table.length
    }), t.getcarslist(t, 0), app.globalData.util.request({
      url: "entry/wxapp/Api",
      data: {
        m: "monai_market",
        r: "sale.salelist.getfee"
      },
      success: function (a) {
        t.onshelffee = a.data.data.onshelffee, t.settopfee = a.data.data.settopfee, t.settoptime = a.data.data.settoptime;
      }
    });
  },
  onShow: function () {
    var a = this;
    a.getcarslist(a, a.activeIndex);
  },
  onReachBottom: function () {
    var s = this,
        n = s.carslist;
    2 != s.dropdown && (s.dropdown = 2, app.globalData.util.request({
      url: "entry/wxapp/Api",
      data: {
        m: "monai_market",
        uid: app.globalData.getuid(),
        leftid: s.page + 1,
        types: s.activeIndex,
        r: "sale.salelist.getlist"
      },
      success: function (a) {
        var t = a.data.data.cars.length;
        if (0 < t) for (var e = 0; e < t; e++) n.push(a.data.data.cars[e]);
        s.setData({
          carslist: n,
          page: s.page + 1
        });
      },
      complete: function () {
        s.dropdown = 1;
      }
    }));
  },
  onReady: function () {},
  onHide: function () {},
  onUnload: function () {},
  onPullDownRefresh: function () {},
  onShareAppMessage: function () {},
  methods: {
    ActiveClick: function (a) {
      var t = this;
      t.setData({
        activeIndex: a.currentTarget.dataset.index,
        page: 1
      }), t.getcarslist(t, a.currentTarget.dataset.index);
    },
    getcarslist: function (t, a) {
      app.globalData.util.request({
        url: "entry/wxapp/Api",
        data: {
          m: "monai_market",
          uid: app.globalData.getuid(),
          leftid: "",
          types: a,
          r: "sale.salelist.getlist"
        },
        success: function (a) {
          t.setData({
            carslist: a.data.data.cars,
            userinfo: a.data.data.user
          });
        }
      });
    },
    upthiscar: function (a) {
      var t = this,
          e = a.detail.formId,
          s = a.currentTarget.dataset.index,
          n = a.currentTarget.dataset.id;
      3 == t.carslist[s].status ? 0 < t.settopfee ? wx.showModal({
        content: "需要支付" + t.settopfee + "元后会置顶" + t.settoptime + "天",
        success: function (a) {
          a.confirm ? t.dosettoppay(n, e) : a.cancel && console.log("用户点击取消");
        }
      }) : t.dosettoppay(n, e) : wx.showModal({
        content: "此商品未上架，请在上架后再进行置顶操作",
        showCancel: !1
      });
    },
    dosettoppay: function (e, s) {
      app.globalData.util.request({
        url: "entry/wxapp/paysettop",
        data: {
          m: "monai_market",
          uid: app.globalData.getuid(),
          car: e
        },
        success: function (t) {
          t.data && t.data.data && 1e3 == t.data.message ? app.globalData.util.request({
            url: "entry/wxapp/Api",
            data: {
              m: "monai_market",
              uid: app.globalData.getuid(),
              car: e,
              r: "sale.salelist.maketop"
            },
            success: function (a) {
              app.globalData.util.request({
                url: "entry/wxapp/Api",
                data: {
                  m: "monai_market",
                  r: "store.send_tel_news",
                  formid: s,
                  uid: app.globalData.getuid(),
                  tel_type: 3
                }
              }), wx.showModal({
                content: a.data.message,
                success: function (a) {
                  wx.reLaunch({
                    url: "/pages/index/index"
                  });
                }
              });
            }
          }) : t.data && t.data.data && !t.data.errno && wx.requestPayment({
            timeStamp: t.data.data.timeStamp,
            nonceStr: t.data.data.nonceStr,
            package: t.data.data.package,
            signType: "MD5",
            paySign: t.data.data.paySign,
            success: function (a) {
              app.globalData.util.request({
                url: "entry/wxapp/Api",
                data: {
                  m: "monai_market",
                  uid: app.globalData.getuid(),
                  car: e,
                  orderid: t.data.data.orderid,
                  r: "sale.salelist.maketop"
                },
                success: function (a) {
                  app.globalData.util.request({
                    url: "entry/wxapp/Api",
                    data: {
                      m: "monai_market",
                      r: "store.send_tel_news",
                      formid: s,
                      uid: app.globalData.getuid(),
                      tel_type: 3
                    }
                  }), wx.showModal({
                    content: a.data.message,
                    success: function (a) {
                      wx.reLaunch({
                        url: "/pages/index/index"
                      });
                    }
                  });
                }
              });
            }
          });
        }
      });
    },
    makeshelf: function (a) {
      var t = this,
          e = a.currentTarget.dataset.index,
          s = a.currentTarget.dataset.id,
          n = t.carslist[e];
      console.log(n), 3 != n.status ? n.status < 2 && 1 != t.userinfo.is_vip ? 0 < t.onshelffee ? wx.showModal({
        content: "需要支付" + t.onshelffee + "元后才能上架哦",
        confirmColor: "#0AC2AE",
        confirmText: "去支付",
        success: function (a) {
          a.confirm && t.dopay(t, s);
        }
      }) : t.dopay(t, s) : 2 != n.status && 1 != t.userinfo.is_vip || wx.showModal({
        content: "是否更改当前状态",
        confirmColor: "#0AC2AE",
        confirmText: "上架",
        success: function (a) {
          a.confirm && app.globalData.util.request({
            url: "entry/wxapp/Api",
            data: {
              m: "monai_market",
              uid: app.globalData.getuid(),
              car: s,
              r: "sale.salelist.onshelf"
            },
            success: function (a) {
              wx.showModal({
                content: a.data.message,
                success: function () {
                  wx.reLaunch({
                    url: "/pages/index/index"
                  });
                }
              });
            }
          });
        }
      }) : wx.showModal({
        content: "是否更改当前状态",
        confirmColor: "#0AC2AE",
        confirmText: "下架",
        success: function (a) {
          a.confirm && app.globalData.util.request({
            url: "entry/wxapp/Api",
            data: {
              m: "monai_market",
              uid: app.globalData.getuid(),
              car: s,
              r: "sale.salelist.downshelf"
            },
            success: function (a) {
              wx.showModal({
                content: a.data.message
              }), t.getcarslist(t, t.activeIndex);
            }
          });
        }
      });
    },
    dopay: function (t, e) {
      app.globalData.util.request({
        url: "entry/wxapp/paysale",
        data: {
          m: "monai_market",
          uid: app.globalData.getuid(),
          car: e
        },
        success: function (a) {
          a.data && a.data.data && 1e3 == a.data.message ? app.globalData.util.request({
            url: "entry/wxapp/Api",
            data: {
              m: "monai_market",
              uid: app.globalData.getuid(),
              car: e,
              r: "sale.salelist.onshelf"
            },
            success: function (a) {
              wx.showModal({
                content: a.data.message
              }), t.getcarslist(t, t.data.activeIndex);
            }
          }) : a.data && a.data.data && !a.data.errno && wx.requestPayment({
            timeStamp: a.data.data.timeStamp,
            nonceStr: a.data.data.nonceStr,
            package: a.data.data.package,
            signType: "MD5",
            paySign: a.data.data.paySign,
            success: function (a) {
              app.globalData.util.request({
                url: "entry/wxapp/Api",
                data: {
                  m: "monai_market",
                  uid: app.globalData.getuid(),
                  car: e,
                  r: "sale.salelist.onshelf"
                },
                success: function (a) {
                  wx.showModal({
                    content: a.data.message
                  }), t.getcarslist(t, t.data.activeIndex);
                }
              });
            }
          });
        }
      });
    },
    downcar: function (a) {
      var t = this,
          e = a.currentTarget.dataset.index,
          s = a.currentTarget.dataset.id,
          n = t.carslist[e];
      console.log(n), wx.showModal({
        content: "确定下架当前汽车么？",
        confirmColor: "#F75F5F",
        confirmText: "下架",
        success: function (a) {
          a.confirm && app.globalData.util.request({
            url: "entry/wxapp/Api",
            data: {
              m: "monai_market",
              uid: app.globalData.getuid(),
              car: s,
              r: "sale.salelist.downshelf"
            },
            success: function (a) {
              wx.showModal({
                content: a.data.message
              }), t.getcarslist(t, t.activeIndex);
            }
          });
        }
      });
    },
    // delcar: function(a) {
    //     var t = this, e = a.currentTarget.dataset.index, s = a.currentTarget.dataset.id, n = t.data.carslist[e];
    //     console.log(n), wx.showModal({
    //         content: "确定删除当前汽车么？",
    //         confirmColor: "#F75F5F",
    //         confirmText: "删除",
    //         success: function(a) {
    //             a.confirm && app.util.request({
    //                 url: "entry/wxapp/Api",
    //                 data: {
    //                     m: "monai_market",
    //                     uid: app.getuid(),
    //                     car: s,
    //                     r: "sale.salelist.delsale"
    //                 },
    //                 success: function(a) {
    //                     wx.showModal({
    //                         content: a.data.message
    //                     }), t.getcarslist(t, t.data.activeIndex);
    //                 }
    //             });
    //         }
    //     });
    // },
    upcar: function (a) {
      var t = a.currentTarget.dataset.id;
      wx.navigateTo({
        url: "/pagesA/saledetail/index?car=" + t
      });
    },
    detile: function (a) {
      var t = app.globalData.getAttr(a, "id");
      wx.navigateTo({
        url: "/pagesA/home/carMessage/carMessage?id=" + t
      });
    }
  }
};
</script>
<style>
@import "./index.css";
</style>